# -*- coding: utf-8 -*-
# @Time : 2021/9/4 9:21
# @Author : 唐宁
# @Site : 订单Dao层
# @File : OrderDao.py
# @Software: PyCharm

from config.DbConnector import getDb
from core.order.dao.provider import OrderDaoProvider
from core.order.dto.OrderVO import OrderVO
from entity.Order import Order


class OrderDao:

    @classmethod
    def getOrderList(cls, dto):
        """
        数据库查询
        :param dto: 查询参数
        :return:  结果
        """
        # 组装sql
        sql = OrderDaoProvider.getOrderList(dto)
        # 查询数据并返回
        return getDb().select_list(sql, OrderVO)

    @classmethod
    def getOrderListPage(cls, dto):
        """
        数据库查询
        :param dto: 查询参数
        :return:  结果
        """
        # 组装sql
        sql = OrderDaoProvider.getOrderList(dto)
        # 查询数据并返回
        return getDb().select_page(sql, dto.page_number, dto.page_size, OrderVO)

    @classmethod
    def getOrderInfo(cls, orderId):
        # 编写sql
        sql = f"SELECT * FROM order_info WHERE id = {orderId}"
        # 查询数据
        return getDb().select_one(sql, Order)

    @classmethod
    def updateOrderNo(cls, orderId, orderNo):
        sql = f"UPDATE order_info SET order_no = {orderNo} WHERE id = {orderId}"
        return getDb().excuse_one(sql)
